package o2o.web.actions.remote;

import com.jinyou.utils.common.AjaxResult;
import o2o.cache.user.UserInfoMemory;
import o2o.cache.user.UserOnlineImpl;
import o2o.dao.PO.user.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * User: Jahnke [1029777564@qq.com]
 * Date: 2018-06-26 10:09
 * 提供远程访问接口-用户管理
 */
@Controller
public class UserRemoteController {

    /**
     *  根据token获取用户账号
     * @param token
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/remote/user/get")
    @ResponseBody
    public String get(String token) {
        String username = UserOnlineImpl.getInstance().get(token);
        return AjaxResult.successResult(username);
    }

    /**
     * 根据token获取用户信息
     * @param token
     * @return
     */
    @RequestMapping(method = RequestMethod.POST, value = "/remote/user/info/get")
    @ResponseBody
    public String getUser(String token) {
        //验证用户有效性
        UserInfo user = UserInfoMemory.getInstance().getUserInfo(UserOnlineImpl.getInstance().get(token));

        return AjaxResult.successResult(user);
    }
}
